﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVC
{
    public class EmployeePresenter
    {
        public IEmployeeView View { get; private set; }
        public EmployeeRepository Repository { get; private set; }
        public EmployeePresenter(IEmployeeView view)
        {
            View = view;
            Repository = new EmployeeRepository();
            View.DepartmentSelected += OnDepartmentSelected;
        }

        public void Initialize()
        {
            IEnumerable<Employee> employees = Repository.GetEmployees();
            View.BindEmployees(employees);
            var departments = new string[] { "", "销售部", "人事部", "采购部", "IT部" };
            View.BindDepartment(departments);
        }

        void OnDepartmentSelected(object sender, DepartmentSelectedEventArgs e)
        {
            string department = e.Department;
            var employees = Repository.GetEmployees(department);
            View.BindEmployees(employees);
        }
    }
}